package com.pkx.guide.record.service.impl;

import com.pkx.guide.info.service.TInfoGuidePublishService;
import com.pkx.guide.record.entity.TRecordGuidePublishTask;
import com.pkx.guide.record.mapper.TRecordGuidePublishTaskMapper;
import com.pkx.guide.record.service.TRecordGuidePublishTaskService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.springframework.transaction.annotation.Transactional;

/**
 * 诱导屏发布任务记录表 服务实现类
 *
 * @author sunsy
 * @since 2023-11-16
 */
@Service
public class TRecordGuidePublishTaskServiceImpl extends ServiceImpl<TRecordGuidePublishTaskMapper, TRecordGuidePublishTask> implements TRecordGuidePublishTaskService {

    /**
     * 分页列表
     *
     * @param tRecordGuidePublishTask
     * @return
     */
    @Override
    public IPage<TRecordGuidePublishTask> pageList(Page page, TRecordGuidePublishTask tRecordGuidePublishTask) {
        LambdaQueryWrapper<TRecordGuidePublishTask> lambdaQueryWrapper = new QueryWrapper<TRecordGuidePublishTask>().lambda();
        return page(page, lambdaQueryWrapper);
    }

    /**
     * 列表查询
     *
     * @param tRecordGuidePublishTask
     * @return
     */
    @Override
    public List<TRecordGuidePublishTask> listByEntity(TRecordGuidePublishTask tRecordGuidePublishTask) {
        LambdaQueryWrapper<TRecordGuidePublishTask> lambdaQueryWrapper = new QueryWrapper<TRecordGuidePublishTask>().lambda();
        lambdaQueryWrapper.eq(TRecordGuidePublishTask::getDelFlg, 0);
        return list(lambdaQueryWrapper);
    }

    /**
     * 列表查询
     *
     * @return
     */
    @Override
    public List<TRecordGuidePublishTask> selectAll(){
        LambdaQueryWrapper<TRecordGuidePublishTask> lambdaQueryWrapper = new QueryWrapper<TRecordGuidePublishTask>().lambda();
        lambdaQueryWrapper.eq(TRecordGuidePublishTask::getDelFlg, 0);
        return list(lambdaQueryWrapper);
    }

    /**
     * 详情
     *
     * @param id
     * @return
     */
    @Override
    public TRecordGuidePublishTask selectById(Integer id) {
        return getById(id);
    }

    /**
     * 保存
     *
     * @param tRecordGuidePublishTask
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean saveTRecordGuidePublishTask(TRecordGuidePublishTask tRecordGuidePublishTask) {
        // 删除当前发布id
        deleteByGuidePublishId(tRecordGuidePublishTask.getGuidePublishId());
        return save(tRecordGuidePublishTask);
    }

    /**
     * 修改
     *
     * @param tRecordGuidePublishTask
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean modify(TRecordGuidePublishTask tRecordGuidePublishTask) {
        return updateById(tRecordGuidePublishTask);
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean deleteById(Integer id) {
        if (id == null){
            return false;
        }
        LambdaUpdateWrapper<TRecordGuidePublishTask> lambdaUpdateWrapper = new UpdateWrapper<TRecordGuidePublishTask>().lambda()
            .eq(TRecordGuidePublishTask::getId, id)
            .set(TRecordGuidePublishTask::getDelFlg, 1);
        return update(lambdaUpdateWrapper);
    }

    /**
     * 删除
     *
     * @param guidePublishId
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean deleteByGuidePublishId(Integer guidePublishId){
        if (guidePublishId == null){
            return false;
        }
        LambdaUpdateWrapper<TRecordGuidePublishTask> lambdaUpdateWrapper = new UpdateWrapper<TRecordGuidePublishTask>().lambda()
                .eq(TRecordGuidePublishTask::getGuidePublishId, guidePublishId)
                .set(TRecordGuidePublishTask::getDelFlg, 1);
        return update(lambdaUpdateWrapper);
    }
}
